package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.google.android.flexbox.JustifyContent;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.adapter.ADVipInfo;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;
import com.zlzxm.shoesmarket.viewmodel.VMVipInfo;

/**
 * CREATE BY zlzxm ON 4/13/21
 */
public class ACVipInfo extends BaseActivity implements OnItemClickListener {


    public static void start(Context context){

        Intent intent = new Intent(context,ACVipInfo.class);

        context.startActivity(intent);

    }


    private VMVipInfo vmVipInfo;

    private RecyclerView rvVipInfo;

    private ADVipInfo adVipInfo = new ADVipInfo(null);

    private TextView tvPriceDesc;

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_vip_info);
        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);
        simpleHead.setTitle("我的会员");
        simpleHead.setOnItemclicklistener(this::finish);

        rvVipInfo = ZViewHelp.findById(this,R.id.rvVipInfo);
        FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(getApplicationContext());
        flexboxLayoutManager.setJustifyContent(JustifyContent.SPACE_BETWEEN);
        rvVipInfo.setLayoutManager(flexboxLayoutManager);

        tvPriceDesc = ZViewHelp.findById(this,R.id.tvPriceDesc);
    }

    @Override
    protected void initViewModule() {
        super.initViewModule();
        vmVipInfo = new ViewModelProvider(this).get(VMVipInfo.class);
        vmVipInfo.getLiveVipInfo().observe(this,adVipInfo::setList);
        vmVipInfo.getLiveErrorToast().observe(this,this::errorToast);
        vmVipInfo.getLiveVipDesc().observe(this,tvPriceDesc::setText);

    }

    @Override
    protected void initData() {
        super.initData();
        rvVipInfo.setAdapter(adVipInfo);
        vmVipInfo.requestVipInfo();
        vmVipInfo.requestVipDesc();

        adVipInfo.setOnItemClickListener(this);

    }


    private String createPriceDesc(){


        return "*VIP会员服务一经开通不支持取消/退款，敬请谅解*\n" +
                "1.此活动由xxxx提供，与apple；\n" +
                "2.购买即同意《VIP会员协议》及《隐私政策》；\n" +
                "3.商品展示划线价格均为参考价格。";
    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

        adVipInfo.setSelectPosition(position);

    }
}
